<!--#include file="common/header.html"-->
<link rel="stylesheet" type="text/css" href="../css/autocomplete.css" media="all">
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/statsRebate/order">
                        <input type="hidden" name="_query.userid" />
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div id="list" class="layui-form"></div>
                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>

    <div class="add-subcat">

    </div>

</body>
<!--#include file="stats-rebate-orderlist.html"-->
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="../js/lib/bootstrap.autocomplete.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');
    function afterTableLoad(data) {
        layui.use(['jquery', 'jqmenu'], function(exports) {
            var jqmenu = layui.jqmenu;
            var menu = new jqmenu();
            menu.menuBind();
        });
    }

    function initData() {
        var uid = getQueryString('userid') || '';
        var json = JSON.parse($("#list-tpl").attr('data-params'));
        json['url'] = json['url'] + '?_query.userid=' + uid;
        $("#list-tpl").attr('data-params', JSON.stringify(json));
        $('input[name="_query.userid"]').val(uid);
    }


    function refreshImg(){
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.photos({
                photos: '.layer-photos-demo'
                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
        });
    }

    /*查看订单返利明细*/
    function _edit(ids, order_no) {
        var index = layer.open({
            type: 2,
            content: "stats-rebate-orderitem.html?ids=" + ids, "title": '【'+ order_no +"】明细", "full":"true"
        });
        layer.full(index);
    }

    var _showImg = function(k, q){
        var arr = q.split(',');
        var content ='';
        for(var i=0; i< arr.length; i++){
            var _url = arr[i];
            var str =  '<img name="file" src="{src}" class="img-thumbnail" style="height:200px;">';
            str = str.replace(/{src}/g, '/education'+_url);
            str = '<span class="layer-photos-demo">' + str + '</span>';
          //  str += '<a style="cursor: pointer;margin-right: 50px;" onclick="delImg(this)"><span class="layui-icon" style="color: red;font-size: xx-large;vertical-align:top;">&#x1006;</span></a>'
            content += '<span>' + str + '</span>';
        }
        var rs = '<div class="imgbox" style="height: 200px;">'+content+'</div>';
        $('input[name='+k+']').parent().after(rs);
    };

    function delImg(obj){
        var input = $(obj).parent().parent().prev().find('input[type=hidden]');
        if($(obj).parent().parent().children('span').length == 1){
            input.val('');
            input.prev().val('');//两张图片的处理
            $(obj).parent().parent().remove();
        } else {
            var v = $(obj).prev().find('img').attr('src').replace('/education', '');
            //先处理两张图片的情况
            if(input.prev('input').length >0){
                if(v == input.prev('input').val()){
                    input.prev('input').val('');
                }else{
                    input.val('');
                }
            } else {
                var s = input.val().replace(','+ v, '')
                        .replace(v +',', '');
                input.val(s);
            }
            $(obj).parent().remove();
        }
    }

    function closeTab(){
        alert(0)
    }

    function _gotoOrder(ids, mobile){
        var index = layer.open({
            type: 2,
            content: "order.html?userid=" + ids, "title": '【'+ mobile +"】订单管理", "full":"true"
        });
        layer.full(index);
    }

</script>
<script>
    function beforeSubmit() {
        if($('#form4').attr('action').indexOf('transfer') > 0) {
            if(!$('#addUserid').val()) {
                layer.msg('请选择需要操作的记录');
                return false;
            }
        }
    }
    function beforeAdd(obj){
        $('#forceDiv').show();
        $('#addUserid').val($('input[name="_query.userid"]').val());
    }
    function beforeTransfer(obj){
        $('#forceDiv').hide();
        var arr = [];
        $("input[name=checkbox]:checked").each(function() {
            arr.push($(this).val());
        });
        var vals = arr.toString();
        if (vals == "") {
            layer.msg('请选择需要操作的记录');
            return;
        }
        $('#addUserid').val(vals);
    }
    $(function(){
        $('#autocompleteInput').autocomplete({
            source:function(query,process){
                var matchCount = this.options.items;//返回结果集最大数量
                $.post("/education/admin/user/query",{"keyword":query, },function(respData){
                    console.log(respData);
                    if(respData.code == 200) {
                        return process(respData.data);
                    }
                });
            },
            formatItem:function(item){
                var name = item["name"] || '';
                var username = item["username"] || '';
                return name +"("+ username + ")";
            },
            setValue:function(item){
                return {'data-value':item["username"],'real-value':item["username"]+'-'+item["id"]};
            }
        });
    });
</script>
</html>